package com.use.utils.db;

import cn.hutool.db.ds.DSFactory;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class TestDbFactory02 {
    public static void main(String[] args) throws SQLException {
        DataSource ds = DSFactory.get("hutool1");
        System.out.println(ds);
        try (Connection connection = ds.getConnection();
             PreparedStatement preparedStatement = connection.prepareStatement("select * from user")) {
            boolean execute = preparedStatement.execute();
            System.out.println(execute);

            if (execute) {
                try (ResultSet resultSet = preparedStatement.getResultSet()) {
                    while (resultSet.next()) {
                        // 获取查询结果中的列值
                        int id = resultSet.getInt("id");
                        String name = resultSet.getString("name");
                        // 打印或处理获取到的值
                        System.out.println("ID: " + id + ", name: " + name);
                    }
                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
